#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <vector>

using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int inf = 1e9, N = 2e5 + 10;

int n;
int a[N];


PII f(int x1, int x2){
    if(x1 < x2){
        int mid = (x1 + x2) / 2;
        return {-inf, mid};
    }else if(x1 > x2){
        int mid = (x1 + x2 + 1) / 2;
        return {mid, inf};
    }else{
        return {-inf, inf};
    }
}

PII merge(PII k1, PII k2){
    int l1 = k1.first, r1 = k1.second;
    int l2 = k2.first, r2 = k2.second;

    if(r1 < l2 || l1 > r2){
        return {-1, -1};
    }else{
        return {max(l1, l2), min(r1, r2)};
    }
}

void solve(){
    cin >> n;
    for(int i = 1; i <= n; i ++) cin >> a[i];

    PII k = f(a[1], a[2]);
  //  cout << k.first << " " << k.second << '\n';
    for(int i = 2; i + 1 <= n; i ++){
        PII t = f(a[i], a[i + 1]);
     //   cout << "i=" << i << " " << t.first << " " << t.second << '\n';
        PII cur = merge(k, t);
        if(cur.second == -1){
            cout << -1 << '\n';
            return;
        }
        k = cur;
    }

    cout << k.second << '\n';

}


int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;
    while(T--){
        solve();
    }


    return 0;
}